package com.mgfireworks.mgplatform.mgadmin.product;

import java.util.List;

import org.apache.commons.lang3.tuple.Triple;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import cn.hn.java.summer.annotation.ParamValid;

import com.mgfireworks.mgplatform.mgadmin.product.model.Band;
import com.mgfireworks.mgplatform.mgadmin.product.model.Category;
import com.mgfireworks.mgplatform.mgadmin.product.model.Product;
import com.mgfireworks.mgplatform.mgadmin.product.model.ProductDetail;
import com.mgfireworks.mgplatform.mgadmin.product.model.SellLevel;

/**
 * 
 * @author nap
 * 20161015-10:19:48
 * 产品控制器
 */
@Controller
@RequestMapping("/product/product")
public class ProductController {

	@Autowired
	ProductService productService;
	@Autowired
	CategoryService categoryService;
	@Autowired
	BandService bandService;
	
	/**
	 * 产品列表
	 * @return
	 */
	@RequestMapping("/list")
	public List<Product> list(Product p){
		return productService.getProducts(p);
	}

	/**
	 * 添加产品
	 */
	@RequestMapping(value="/add",method=RequestMethod.GET)
	public Triple<List<Category>, List<Band>, List<SellLevel>> add(){
		return Triple.of(categoryService.getAllCategorys(), bandService.getAllBands(), null);
	}
	
	/**
	 * 提交添加产品
	 */
	@RequestMapping(value="/add",method=RequestMethod.POST)
	public void postAdd(@ParamValid Product p, ProductDetail pd){
		productService.addProduct(p,pd);
	}

	/**
	 * 编辑产品
	 */
	@RequestMapping(value="/edit",method=RequestMethod.GET)
	public Product edit(Product p){
		return productService.getProduct(p);
	}
	
	/**
	 * 提交编辑产品
	 */
	@RequestMapping(value="/edit",method=RequestMethod.POST)
	public void postEdit(@ParamValid Product p){
		productService.editProduct(p);
	}
	
	/**
	 * 获取产品
	 */
	@RequestMapping(value="/get",method=RequestMethod.GET)
	public Product get(Product p){
		return productService.getProduct(p);
	}
	
	/**
	 * 删除产品
	 */
	@RequestMapping("/del")
	public void del(Product p){
		productService.delProduct(p);
	}
}